package com.ljw.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ljw.dto.BookDto;
import com.ljw.dto.CheckOutDto;
import com.ljw.dto.MoveInDto;
import com.ljw.service.MoveService;
import com.ljw.service.UserService;
import com.ljw.vo.MoveVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 入住信息表 前端控制器
 * </p>
 *
 * @author ljw
 * @since 2020-07-25
 */
@RestController
@RequestMapping("/move")
public class MoveController {

    @Autowired
    private MoveService moveService;

    @Autowired
    private UserService userService;

    @GetMapping("/findAll")
    public Page<MoveVo> findAll(@RequestParam int userId, @RequestParam int current, @RequestParam int size){
        int userPower = userService.getById(userId).getUserPower();
        Page<MoveVo> page = new Page<>(current,size);
        if(userPower == 1){
            return moveService.findAll(page,0);
        }else {
            return moveService.findAll(page,userId);
        }
    }

    //入住
    @PostMapping("/moveIn")
    @Transactional
    public String moveIn(@RequestBody MoveInDto moveInDto){
        return moveService.moveIn(moveInDto);
    }

    //退房
    @PostMapping("/checkOut")
    public String checkOut(@RequestBody CheckOutDto checkOutDto){
        return moveService.checkOut(checkOutDto);
    }

    //直接办理入住
    @PostMapping("/bookAndMoveIn")
    public String bookAndMoveIn(@RequestBody BookDto bookDto){
        return moveService.bookAndMoveIn(bookDto);
    }

}

